<?php

class Secretaria extends DataMapper {

	var $error_prefix = '<div class="alert alert-danger" role="alert">';
    var $error_suffix = '</div>';
	
    var $table = 'secretarias';
	
	var $has_many = array("setor");
	
	var $validation = array(
		'sigla' => array(
			'label' => 'Sigla',
			'rules' => array('required')
		),
		'nomesecretaria' => array(
			'label' => 'Secretaria',
			'rules' => array('required')
		)
	);

    function __construct($id = NULL)
    {
        parent::__construct($id);
    }
	
	public function consultaSecretaria(){
	
		$secretaria = new Secretaria();
		$secretaria = $secretaria->get();
		
		$aux = array();
		$aux[""] = " -- SELECIONE A SECRETARIA --";
		foreach($secretaria as $s){
			$aux[$s->id ] = $s->nomesecretaria;
		}
	
		return $aux;
	
	}
	public function relatorioramais($id = null){
	
		$result = $this->db->query("
		SELECT secretarias.id, secretarias.sigla, secretarias.nomesecretaria
		FROM secretarias
		GROUP BY sigla;
		");
		
		
		$sec = new Secretaria();
		$sec->_process_query($result);
		
		return $sec;
	}
	public function relatoriolocais($id = null){
	
		$result = $this->db->query("
		SELECT secretarias.id, secretarias.sigla, secretarias.nomesecretaria, setores.id as setor_id
		FROM secretarias
		LEFT JOIN setores ON setores.secretaria_id = secretarias.id
		WHERE setores.id = '$id'
		");
		
		
		$sec = new Secretaria();
		$sec->_process_query($result);
		
		return $sec;
	}
}

/* End of file evento.php */
/* Location: ./application/models/evento.php */
